<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateIotTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('iot', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('user_id')->index()->comment('用户id');
            $table->unsignedInteger('device_id')->index()->comment('设备id');
            $table->unsignedMediumInteger('type')->default(0)->comment('默认  0 dtu_device  其他保留');
            $table->unsignedInteger('timestamp')->index()->comment('上传时间戳');
            $table->string('name')->comment('字段名  同一用户下不可重复');
            $table->string('description')->comment('字段描述');
            $table->string('unit')->nullable()->comment('单位');
            $table->string('expression')->nullable()->comment('表达式');
            $table->unsignedTinyInteger('is_alert')->default(0)->comment('默认 0不告警 1告警');
            $table->decimal('upper_limit',18,3)->defaul(0)->comment('上限');
            $table->decimal('lower_limit',18,3)->defaul(0)->comment('下限');
            $table->unsignedSmallInteger('sort')->detault(0)->comment('排序 越大越前');
            /**
             * machine_info['']
             *
             */
            $table->text('info')->nullable()->comment('设备信息');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('iot');
    }
}
